
/* 
 * This file is part of FreeBMS - an open source battery management system
 *
 * Message Code Headers
 * 
 * NOTE: This code is designed to be compiled using SOURCEBOOST (http://www.sourceboost.com)
 */
 
/* This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
#ifndef _CODES_H_
#define _CODES_H_

// Serial Message Type ID Codes
#define ID_WAKEUP			0x00	// Request chips to wake up
#define ID_START_VOLT		0x01	// Request to start voltage conversion
// EMPTY					0x02
#define ID_VOLT				0x03	// Message request for voltage
// EMPTY					0x04
#define ID_SHUNT			0x05	// Message to enable/disable shunting
#define ID_PROGRAM_ID		0x06	// Message to program the chip ID
#define ID_PROGRAM_ERROR	0x07	// Message to program the error correction percentage (LEAD ACID)
#define ID_PROGRAM_CUTOFFS	0x08	// Message to program the cutoff voltages
#define ID_PROGRAM_TIMERS	0x09	// Message to program the shunting timers
#define ID_PROGRAM_LEDS		0x0A	// Message to program LED configurations
#define ID_PROGRAM_DELAY	0x0B	// Message to program ADC shunting delay

// CANBUS Message Codes
#define CAN_ID_BCAST1		0x30	// CAN message broadcast #1 (100ms)
#define CAN_ID_BCAST2		0x31	// CAN message broadcast #2 (100ms)
#define CAN_ID_BCAST3		0x32	// CAN message broadcast #3 (50ms)
#define CAN_ID_DTC			0x33	// CAN message indicating a DTC has occurred
#define CAN_ID_CONFIG		0x34	// CAN message indicating an incoming config message
#define CAN_ID_RESPONSE		0x35	// CAN message replying to configuration message
#define CAN_ID_CELLBCAST	0x36	// CAN message broadcasting individual cell voltages

// Programming Message IDs
#define CONFIG_OPMODE		0x00	// Change the current operation mode
#define CONFIG_NUMCELLS		0x01	// Change the number of chips in BMS
#define CONFIG_MINVOLT		0x02	// Change the voltage cutoffs for chips
#define CONFIG_MAXVOLT		0x03	// Change the voltage cutoffs for chips
#define CONFIG_DIFFVOLT		0x04	// Change the difference voltage for shunting
#define CONFIG_BALVOLT		0x05	// Change the minimum balancing voltage
#define CONFIG_TIMERPAUSE	0x06	// Change the duration of pause between balancing
#define CONFIG_TIMERSHUNT	0x07	// Change the duration of balancing
#define CONFIG_AMPHOURS		0x08	// Change the current amphour counter
#define CONFIG_AMPFULL		0x09	// Change the amphour counter for full battery
#define CONFIG_AMPEMPTY		0x0A	// Change the amphour counter for empty battery
#define CONFIG_SENSORCALIB	0x0B	// Calibrate the current sensor error correction
#define CONFIG_BATTERYSOC	0x0C	// Change the current SOC counter
#define CONFIG_BAUDRATE		0x0D	// Change the serial baud rate
#define CONFIG_SHUNTING		0x0E	// Change whether shunting is enabled

// Regulator configuration messages
#define CONFIG_REG_TIMERS	0x0F	// Regulator safety timers
#define CONFIG_REG_CUTOFFS	0x10	// Regulator safety cutoff voltages
#define CONFIG_REG_ADCDELAY	0x11	// Regulator ADC delay 
#define CONFIG_REG_LEDMODE	0x12	// Regulator LED configuration
#define CONFIG_REG_ERROR	0x13	// Regulator error percentage (Lead Acid)
#define CONFIG_REG_SHUNTREQ	0x14	// Request a regulator shunt

// Message Error ID Codes
#define ERROR_NO_TRAFFIC	0x01 	// No serial traffic for extended period of time
#define ERROR_COMM_ERRORS	0x02	// Communication errors experienced
#define ERROR_LOW_VOLTAGE	0x03 	// Low voltage in a cell
#define ERROR_HI_VOLTAGE	0x04 	// High voltage in a cell
#define ERROR_LOW_TEMP		0x05 	// Low temperature for pack
#define ERROR_HI_TEMP		0x06 	// High temperature for pack
#define ERROR_MEM_FAULT		0x07	// Memory inconsitency in supervisor
#define ERROR_TRIS_FAULT	0x08	// One of the output registers faulted
#define ERROR_SENSOR_FAULT	0x09	// No current sensor detected (or bogus values)
#define ERROR_CELL_FAULT	0x0A	// Bad regulator cell
#define ERROR_RELAY_FAULT	0x0B	// Relays are not cutting off current flow
#define ERROR_CAN_ERRORS	0x0C	// Too many CANBUS errors experienced

#define ERROR_LOAD_DTCS		0xF0	// Load DTCs stored in EEPROM
#define ERROR_CLEAR_DTCS	0xF1	// Clear DTCs stored in EEPROM and currently active

#endif // _CODES_H_